<?php

/**
 * Created by PhpStorm.
 * User: shwy
 * Date: 2017/12/22
 * Time: 14:45
 * 统计分析管理相关接口
 */
class Statement extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('purchaseOrder_model');
        $this->load->model('returnOrder_model');
        $this->load->model('goods_model');
        $this->load->model('supplier_model');
        $this->load->model('project_model');
        $this->load->model('stockPut_model');
        $this->load->model('stockOut_model');
    }

    /**
     * 采购订单统计报表
     * $param string search 不同类型不同搜索（数据库中是supplier字段)。
     * $param string type 类型判断是什么类型,参数（gys 、order 、project）。
     */
    public function orderSearch()
    {
    	// 采购统计汇总传来
    	$get = $this->input->get();
		// 获取搜索的where 条件, 时间, 商品名称 
		$where = [];		
		if ($get['startTime']) {
			$where += [
                'createTime >' => strtotime($get['startTime'])
            ];
		} 
		if ($get['endTime']) {
			$where += [
                'createTime <' => strtotime($get['endTime'])
            ];
		} 
		$search = $get['search'] ? trim($get['search']) : '';

		// 返回的error 的数据
		$error = [
	        'error' => true,
	        'info' => '没有查询到信息'
        ];

		$type = isset($get['type']) ? $get['type'] : 'goods';

		$per_nums = $this->config->item('fenye')['pageNum']; //每页的数据
        $start_position = 0; //初始数据
        $page = $get['page']; //获取页码数量
        if ($page) {
            $start_position = ($page - 1) * $per_nums;
        }

		// where 添加
        $where += [
            'status' => 5
        ];
		$fields = 'id, supplier, goodsMessage, createTime, endTime, name, purchaseCode, status, source';

		// 按输入type 进行判断
		if ($type == 'goods') {
			$data = $this->purchaseOrder_model->paging($fields, $where, $per_nums, $start_position);
				if ($data['total_num'] != 0) {
					$count = $data['total_num'];
					unset($data['total_num']);
					foreach ($data as $k => $v) {
						// 格式化goodsMessage json字符串
		                $data[$k]['goodsMessage'] = json_decode($data[$k]['goodsMessage'], true);
						foreach ($data[$k]['goodsMessage'] as $k1 => $v1) {
	                		$data[$k]['goodsMessage'][$k1]['supplier'] = $data[$k]['supplier'];
	                	}
					}

					// 把格式化的字符串放入一个新数组中
	                foreach ($data as $v2) {
	                    foreach ($v2['goodsMessage'] as $v3) {
	                        if (!$v3['price']) continue;
	                        $new[] = $v3;
	                    }
	                }
					
					if ($search != '') {
						$newArr = [];						
						// 通过search找出结果		
						foreach ($new as $v10) {
							if (is_numeric(stripos($v10['name'], $search))) {
								$newArr[] = $v10;
//								echo 'hello';
//								exit;
							}																																							
						}
						if (empty($newArr)) {
//							echo 'no';
							die(json_encode($error, JSON_UNESCAPED_UNICODE));
						}						
//						dd($newArr);
						$new = [];
						$new = $newArr;						
					}
					
					// 再根据product_no 相同，放入一个数组
	                foreach ($new as $v4) {
	                    $res[$v4['product_no']][] = $v4;
	                }
					
					// 统计合计数量金和合计金额
	                foreach ($res as $k5 => $v5) {
	                    $new2[$k5]['quantity'] = array_sum(array_column($v5, 'quantity'));
	                    $new2[$k5]['priceAll'] = number_format(array_sum(array_column($v5, 'priceAll')), 2);
	                }
					// 再根据新数组的key查询商品表
	                foreach ($new2 as $k6 => $v6) {
	                    $arg = [
	                        'product_no' => $k6
	                    ];					
						$goodsFields = 'id, ckId,product_no,name,source,one_category,supplier';	               
	                    $goods[] = $this->goods_model->getByFieldQueryData($goodsFields, $arg, 0);
	                }
	                $goods = array_filter($goods);
					
					// 2物料包、3书籍、4机器耗材、9打印机租赁、8供应商商品
	                foreach ($goods as $k => $v) {
	//                  $dataId = $v['ckId'] ? $v['ckId'] : $v['id'];
	                    switch ($v['one_category']){
	                        case 2:
	                            $goods[$k]['one_category'] = "物料包";
	                            break;
	                        case 3:
	                            $goods[$k]['one_category'] = "书籍";
	                            break;
	                        case 4:
	                            $goods[$k]['one_category'] = "机器耗材";
	                            break;
	                        case 8:
	                            $goods[$k]['one_category'] = "供应商商品";
	                            break;
	                        case 9:
	                            $goods[$k]['one_category'] = "打印机租赁";
	                            break;
	                    }
	                }	
	//				dd($goods);
	                foreach ($new2 as $k7 => $v7) {
	                    foreach ($goods as $k8 => $v8) {
	                        if ($k7 == $v8['product_no']) {
	                            $goods[$k8]['quantity'] = $v7['quantity'];
	                            $goods[$k8]['priceAll'] = $v7['priceAll'];
	                        }
	                    }
	                }
					foreach ($goods as $k9 => $v9) {
	                    foreach ($res as $k10 => $v10) {
	                        if ($v9['product_no'] == $k10) {
	                            $goods[$k9]['specification222'] = $v10;
	                            break;
	                        } else {
	                            $goods[$k9]['specification222'] = 5213;
	                        }
	                    }
	                }
	//				dd($goods);
	                foreach ($goods as $k11 => $v11) {
	                    foreach ($data as $v10) {
	                        $goods[$k11]['createTime'] = $v10['createTime'];
	                        $goods[$k11]['endTime'] = $v10['endTime'];
	                    }
	                }
					$data = [
						'pageNum'  		=> $per_nums,						
						'totalNum' 		=> $count,
						'currentPage'	=> $page,
						'goods'			=> $goods					
						];
					echo die(json_encode($data, JSON_UNESCAPED_UNICODE));										
				} else {
					die(json_encode($error, JSON_UNESCAPED_UNICODE));
				}
				
//	以上是按商品名称搜索, 由于数据库设计不当, 所以只能这样. 甚是麻烦, 但还是得做-----------------------
		} else {
			switch ($type) {
				case 'gys':
            	// 搜索供应商名
            		$field = 'supplier';                   
					break;
					
				case 'order':
            	// 搜索供应商名
            		$field = 'name';                   
					break;
					
				case 'project':
            	// 搜索供应商名
            		$field = 'source';                   
					break;
			}

			if ($search != '') {							 	
            	$like = [
                    'field' => $field,
                    'arg'	=> $get['search'],
                    'side' 	=> 'both'
                ];
            } else {
				$like = '';
			}	

	        if ($like != '') {
	            $data = $this->purchaseOrder_model->pagingLike($fields, $where, $like, $per_nums, $start_position);
	        } else {
				$data = $this->purchaseOrder_model->paging($fields, $where, $per_nums, $start_position);
	        }
//			dd($data);
			// 查询做好了, 判断数据
			if ($data) {
				if (isset($data['total_num'])) {
					$count = $data['total_num'];
					unset($data['total_num']);
				} else {
					$count = count($data);	
				}							
								
				foreach ($data as $k => $v) {
					// 格式化goodsMessage json字符串
	                $data[$k]['goodsMessage'] = json_decode($data[$k]['goodsMessage'], true);
				}

				// 开始进行判断
				switch ($type) {
					case 'gys':
					// 当类型位供应商	
						foreach ($data as $k => $v) {		                    
		                    $arg = [
		                        'name' => $v['supplier']
		                    ];
		                    $supplier[] = $this->supplier_model->getByFieldQueryData('id,name,code,type,linkMan,address', $arg, 0);
		                }
		
		                // 根据供应商相同整合数据
		                foreach ($data as $k2 => $v2) {
		                    $res[$v2['supplier']][] = $v2;
		                }
						
		                foreach ($res as $k3 => $v3) {
		
		                    //预定义变量防止报错Undefined index：xxxx
		                    $res[$k3]['quantity'] = [];
		                    $res[$k3]['priceAll'] = [];
		
		                    foreach ($v3 as $k4 => $v4) {
		                        //查询总商品数量和采购金额
		                        $res[$k3]['quantity'][] .= array_sum(array_column($v4['goodsMessage'], 'quantity'));
		                        $res[$k3]['priceAll'][] .= array_sum(array_column($v4['goodsMessage'], 'priceAll'));
		                    }
		
		                    foreach ($supplier as $v5) {
		                        if ($k3 == $v5['name']) {
		                            $res[$k3]['code'] = $v5['code'];
		                            $res[$k3]['type'] = $v5['type'];
		                            $res[$k3]['supplierId'] = $v5['id'];
		                            $res[$k3]['linkMan'] = $v5['linkMan'];
		                            $res[$k3]['address'] = $v5['address'];
		                        }
		                    }
		                }
						
		                //删除多余数据
		                foreach ($res as $k6 => $v6) {
		                    foreach ($v6 as $k7 => $v7) {
		                        if (is_numeric($k7)) {
		                            unset($res[$k6][$k7]);
		                        }
		                    }
		                }
						// 结果总数(为分页)						
						$count = count($res);
						break;
					
					case 'order':
						// 按照订单的搜索
			            // 只需直接读取$data的数据进行返回			
			            foreach ($data as $k2 => $v2) {
			                $data[$k2]['quantity']   = array_sum(array_column($v2['goodsMessage'], 'quantity'));
			                $data[$k2]['priceAll']   = number_format(array_sum(array_column($v2['goodsMessage'], 'priceAll')), 2);
							// 时间改了
							$data[$k2]['createTime'] = date('Y-m-d', $v2['createTime']); 
			                unset($data[$k2]['goodsMessage']);
			            }
						$res = $data;						
						break;	
						
					case 'project':
						// 按照订单的搜索
			            foreach ($data as $k => $v) {	
			                $arg = [
			                    'name' => $v['source']
			                ];
			                $project[] = $this->project_model->getByFieldQueryData('id,name,code,linkMan,createTime', $arg, 0);
			            }
			
			            foreach ($data as $k2 => $v2) {
			                $res[$v2['source']][] = $v2;
			            }
			
			            foreach ($res as $k3 => $v3) {
			                $res[$k3]['quantity'] = [];
			                $res[$k3]['priceAll'] = [];
			                foreach ($v3 as $k4 => $v4) {
			                    // 查询总商品数量和采购金额
			                    $res[$k3]['quantity'][] .= array_sum(array_column($v4['goodsMessage'], 'quantity'));
			                    $res[$k3]['priceAll'][] .= array_sum(array_column($v4['goodsMessage'], 'priceAll'));
			                }

			                foreach ($project as $v5) {
			                    if ($k3 == $v5['name']) {
			                        $res[$k3]['code'] = $v5['code'];
			                        $res[$k3]['projectId'] = $v5['id'];
			                        $res[$k3]['linkMan'] = $v5['linkMan'];
			                        $res[$k3]['createTime'] = date('Y-m-d', $v5['createTime']);
			                    }
			                }
			            }
						
			            // 删除多余数据
			            foreach ($res as $k6 => $v6) {
			                foreach ($v6 as $k7 => $v7) {
			                    if (is_numeric($k7)) {
			                        unset($res[$k6][$k7]);
			                    }
			                }
			            }

						$count = count($res);						
						break;				
				}
				$data = [
						'pageNum'		=> $per_nums,						
						'totalNum' 		=> $count,
						'currentPage'	=> $page,
						'goods'			=> $res						
					];
				echo die(json_encode($data,JSON_UNESCAPED_UNICODE));
				
			} else {
				die(json_encode($error,JSON_UNESCAPED_UNICODE));
			}							
		}
	}	        		   


    /**
     * 采购质量统计报表根据供应商搜索 -  搜索供应商名字
     * $param string search 供应商名字（数据库中是supplier字段)。
     * $param string type 类型判断是退货还是换货,参数（returnOrder 、barterOrder）。
     */
    public function qualityBySupplierSearch(){

        //搜索条件开始时间和结束时间
        $argc = [];
        if(isset($_GET['startTime'])  && $_GET['startTime']){
            $argc += [
                'createTime >'=> strtotime($_GET['startTime']),
            ];
        }

        if(isset($_GET['endTime'])  && $_GET['endTime']){
            $argc += [
                'createTime <'=> strtotime($_GET['endTime']),
            ];
        }

        //两个类型退货统计和换货统计
        $type = isset($_GET['type']) ? $_GET['type'] : 'returnOrder';

        //搜索供应商名
        if(isset($_GET['search']) && $_GET['search']){
            $searchArg = [
                'field' => 'supplier',
                'arg'=> $_GET['search'],
                'side' => 'both'
            ];
        }else{
            $searchArg = '';
        }

        switch ($type){
            case 'returnOrder';
                $argc += [
                    'type' => '采购退货单'
                ];
                break;
            case 'barterOrder';
                $argc += [
                    'type' => '采购换货单'
                ];
                break;
        }

//        __format($argc);

        $page_num = $this->config->item('fenye')['pageNum']; //每页的数据
        $start_position = ''; //初始数据
        $page = ($this->input->get('page')); //获取页码数量
        if(!$page){
            $num = 1;
            $start_position = ($num - 1) * $page_num;
        }else{
            $start_position = ($page - 1) * $page_num;
        }

        if(!$argc){
            $argc = 0;
        }

        $field = '*';
        //读取采购进货单的goodMessage数据。

        if($searchArg){
//            $data = $this->returnOrder_model->search($field,$argc,$searchArg,$page_num,$start_position);
            $data = $this->returnOrder_model->getDataSearch($field,$argc,$searchArg);
        }else{
//            $data = $this->returnOrder_model->page('returnOrder', $argc, $page_num, $start_position, $field);
            $data[0] = $this->returnOrder_model->getByFieldQueryData($field, $argc, 1);
        }

        $error = [
            'error' => true,
            'info' => '没有查询到信息'
        ];

        if(!$data[0]){
            die(json_encode($error,JSON_UNESCAPED_UNICODE));
        }

        if($type == 'returnOrder'){
            if($data){
                foreach ($data[0] as $k => $v) {
                    $data[0][$k]['goodsMessage'] = json_decode($data[0][$k]['goodsMessage'], true);


                    $arg = [
                        'name' => $v['supplier']
                    ];
                    $supplier[] = $this->supplier_model->getByFieldQueryData('id,name,code,type', $arg, 0);
                }


//__format($supplier);
//            $res = array();
                //根据供应商相同整合数据，key使用供应商name当做
                foreach ($data[0] as $k2 => $v2) {
                    $res[0][$v2['supplier']][] = $v2;
                }

                foreach ($res[0] as $k3 => $v3) {

                    //预定义变量防止报错Undefined index：xxxx
                    $res[0][$k3]['quantity'] = [];

                    foreach ($v3 as $k4 => $v4) {
                        //查询总商品数量和采购金额
                        $res[0][$k3]['quantity'][] .= array_sum(array_column($v4['goodsMessage'], 'quantity'));
                    }
                    //因为k3 此时 == 供应商的name  然后和供应商的name判断
                    foreach ($supplier as $v5) {

                        if ($k3 == $v5['name']) {
                            $res[0][$k3]['code'] = $v5['code'];
                            $res[0][$k3]['type'] = $v5['type'];
                            $res[0][$k3]['supplierId'] = $v5['id'];
                        }
                    }
                }

                //删除多余数据，就是删除key= 0，1，2的数据，因为需要的数据已经取出来了
                //到此，退货单的数据已经完毕。
                foreach ($res[0] as $k6 => $v6) {
                    foreach ($v6 as $k7 => $v7) {
                        if (is_numeric($k7)) {
                            unset($res[0][$k6][$k7]);
                        }
                    }
                }

//            __format($res);

                //这里开始统计进货单的数据，主要是为了统计列表中 采购进货数量 字段
                //一下的步骤就跟上面类似
                foreach ($res[0] as $k8 => $v8) {
                    $field2 = 'id,name,supplier,goodsMessage,createTime,endTime,name,purchaseCode,status,source,attribute';

                    $arg2 = [
                        'supplier' => $k8
                    ];

                    $purchaseOrder[] = $this->purchaseOrder_model->getByFieldQueryData($field2, $arg2, 1);
                }

//            __format($purchaseOrder);

                //循环进货单的数据，找出attribute字段， 种类/数量
                //利用字符串技术，查出后面的数量字段，再用 供应商 名字当key
                foreach ($purchaseOrder as $k9=>$v9){
                    foreach ($v9 as $k10=>$v10){
                        $attribute[$v10['supplier']][] = substr($v10['attribute'],strpos($v10['attribute'],'/')+1,strlen($v10['attribute']));
                    }
                }

//            __format($res);
                // 和 res数据比较key是否相同，相同则就加入
                foreach ($res[0] as $k11=>$v11){
                    foreach ($attribute as $k12=>$v12){
                        if($k11 == $k12){
                            $res[0][$k11]['purchaseNum'] = array_sum($v12);
                        }
                    }
                }
            }
        }elseif ($type == 'barterOrder'){

            foreach ($data[0] as $k => $v) {
                $data[0][$k]['goodsMessage'] = json_decode($data[0][$k]['goodsMessage'], true);


                $arg = [
                    'name' => $v['supplier']
                ];
                $supplier[] = $this->supplier_model->getByFieldQueryData('id,name,code,type', $arg, 0);
            }

//__format($supplier);
//            $res = array();
            //根据供应商相同整合数据
            foreach ($data[0] as $k2 => $v2) {
                $res[0][$v2['supplier']][] = $v2;
            }

            foreach ($res[0] as $k3 => $v3) {

                //预定义变量防止报错Undefined index：xxxx
                $res[0][$k3]['quantity'] = [];


                foreach ($v3 as $k4 => $v4) {
                    //查询总商品数量和采购金额
                    $res[0][$k3]['quantity'][] .= array_sum(array_column($v4['goodsMessage'], 'quantity'));
                }

                foreach ($supplier as $v5) {
                    if ($k3 == $v5['name']) {
                        $res[0][$k3]['code'] = $v5['code'];
                        $res[0][$k3]['type'] = $v5['type'];
                        $res[0][$k3]['supplierId'] = $v5['id'];
                    }
                }
            }

            //删除多余数据，就是删除key= 0，1，2的数据，因为需要的数据已经取出来了
            //到此，退货单的数据已经完毕。
            foreach ($res[0] as $k6 => $v6) {
                foreach ($v6 as $k7 => $v7) {
                    if (is_numeric($k7)) {
                        unset($res[0][$k6][$k7]);
                    }
                }

            }

//            __format($res);


            //这里开始统计进货单的数据，主要是为了统计列表中 采购进货数量 字段
            //一下的步骤就跟上面类似
            foreach ($res[0] as $k8 => $v8) {
                $field2 = 'id,supplier,goodsMessage,createTime,endTime,name,purchaseCode,status,source,attribute';

                $arg2 = [
                    'supplier' => $k8
                ];

                $purchaseOrder[] = $this->purchaseOrder_model->getByFieldQueryData($field2, $arg2, 1);
            }

//            __format($purchaseOrder);
            //            __format($purchaseOrder);

            //循环进货单的数据，找出attribute字段， 种类/数量
            //利用字符串技术，查出后面的数量字段，再用 供应商 名字当key
            foreach ($purchaseOrder as $k9=>$v9){
                foreach ($v9 as $k10=>$v10){
                    // substr 最后一个参数不填，则表示到字符串结尾
                    $attribute[$v10['supplier']][] = substr($v10['attribute'],strpos($v10['attribute'],'/')+1);
//                    $attribute[$v10['supplier']][] = substr($v10['attribute'],strpos($v10['attribute'],'/')+1,strlen($v10['attribute']));
                }
            }



//            __format($res);
            // 和 res数据比较key是否相同，相同则就加入
            foreach ($res[0] as $k11=>$v11){
                foreach ($attribute as $k12=>$v12){
                    if($k11 == $k12){
                        $res[0][$k11]['purchaseNum'] = array_sum($v12);
                    }
                }
            }

        }



//        foreach ($data[0] as $k=>$v){
//            unset($data[0][$k]['goodsMessage']);
//        }
//
//        __format($data);
//
//
        $res['pageNum'] = $page_num;
        //如果$page 为空则为默认数量
        $res['this_page'] = $page;
//        $res['total_num'] = $data['total_num'];
        $res['total_num'] = count($res);
        $res['type'] = $type;


        echo json_encode($res,JSON_UNESCAPED_UNICODE);

    }



    /**
     * 出入库统计报表根据供应商统计 -  搜索供应商名字
     * $param string search 供应商名字（数据库中是supplier字段)。
     * $param string type 类型判断是出库还是入库,参数（put 、out）。
     */
    public function outAndPutBySupplierSearch(){

        //搜索条件开始时间和结束时间
        $argc = [];
        if(isset($_GET['startTime'])  && $_GET['startTime']){
            $argc += [
                'createTime >'=> strtotime($_GET['startTime']),
            ];
        }

        if(isset($_GET['endTime'])  && $_GET['endTime']){
            $argc += [
                'createTime <'=> strtotime($_GET['endTime']),
            ];
        }

        //两个类型退货统计和换货统计
        $type = isset($_GET['type']) ? $_GET['type'] : 'put';

        //搜索供应商名
        if(isset($_GET['search']) && $_GET['search']){
            $searchArg = [
                'field' => 'supplier',
                'arg'=> $_GET['search'],
                'side' => 'both'
            ];
        }else{
            $searchArg = '';
        }


//        __format($argc);

        $page_num = $this->config->item('fenye')['pageNum']; //每页的数据
        $start_position = ''; //初始数据
        $page = ($this->input->get('page')); //获取页码数量
        if(!$page){
            $num = 1;
            $start_position = ($num - 1) * $page_num;
        }else{
            $start_position = ($page - 1) * $page_num;
        }

        if(!$argc){
            $argc = 0;
        }

        $field = '*';
        //读取采购进货单的goodMessage数据。

        if($type == 'put'){
            if($searchArg){
//                $data = $this->stockPut_model->search($field,$argc,$searchArg,$page_num,$start_position);
                $data = $this->stockPut_model->getDataSearch($field,$argc,$searchArg);
            }else{
//                $data = $this->stockPut_model->page('stockPut', $argc, $page_num, $start_position, $field);
                $data[0] = $this->stockPut_model->getData('*', 1);
            }
        }elseif ($type == 'out'){
            if($searchArg){
//                $data = $this->stockOut_model->search($field,$argc,$searchArg,$page_num,$start_position);
                $data = $this->stockOut_model->getDataSearch($field,$argc,$searchArg);
            }else{
//                $data = $this->stockOut_model->page('stockOut', $argc, $page_num, $start_position, $field);
                $data[0] = $this->stockOut_model->getData('*', 1);
            }
        }

//        __format($data);

        $error = [
            'error' => true,
            'info' => '没有查询到信息'
        ];

        if(!$data[0]){
            die(json_encode($error,JSON_UNESCAPED_UNICODE));
        }

        if($data[0]){

            foreach ($data[0] as $k => $v) {
                $data[0][$k]['goodsMessage'] = json_decode($data[0][$k]['goodsMessage'], true);


                $arg = [
                    'name' => $v['supplier']
                ];
                $supplier[] = $this->supplier_model->getByFieldQueryData('id,name,code,type,linkMan,address', $arg, 0);
            }

//            __format($supplier);

            //根据供应商相同整合数据
            foreach ($data[0] as $k2 => $v2) {
                $res[0][$v2['supplier']][] = $v2;
            }

//            __format($res);
            foreach ($res[0] as $k3 => $v3) {

                //预定义变量防止报错Undefined index：xxxx
                $res[0][$k3]['quantity'] = [];
                $res[0][$k3]['priceAll'] = [];

                foreach ($v3 as $k4 => $v4) {
                    //查询总商品数量和采购金额
                    $res[0][$k3]['quantity'][] .= array_sum(array_column($v4['goodsMessage'], 'quantity'));
                    $res[0][$k3]['priceAll'][] .= array_sum(array_column($v4['goodsMessage'], 'priceAll'));

                    $res[0][$k3]['createMan'] = $v4['createMan'];

                }

                foreach ($supplier as $v5) {
                    if($v5){
                        if ($k3 == $v5['name']) {
                            $res[0][$k3]['code'] = $v5['code'];
                            $res[0][$k3]['type'] = $v5['type'];
                            $res[0][$k3]['supplierId'] = $v5['id'];
                            $res[0][$k3]['linkMan'] = $v5['linkMan'];
                        }
                    }

                }
            }


            //删除多余数据
            foreach ($res[0] as $k6 => $v6) {
                foreach ($v6 as $k7 => $v7) {
                    if (is_numeric($k7)) {
                        unset($res[0][$k6][$k7]);
                    }
                }

            }
        }

        $res['pageNum'] = $page_num;
        //如果$page 为空则为默认数量
        $res['this_page'] = $page;
//        $res['total_num'] = $data['total_num'];
        $res['total_num'] = count($res);
        $res['type'] = $type;


        echo json_encode($res,JSON_UNESCAPED_UNICODE);

    }


    /**
     * 出入库统计报表根据项目统计 -  搜索项目名字
     * $param string search 项目名字（数据库中是source字段)。
     * $param string type 类型判断是出库还是入库,参数（put 、out）。
     */
    public function outAndPutByProjectSearch(){

        //搜索条件开始时间和结束时间
        $argc = [];
        if(isset($_GET['startTime'])  && $_GET['startTime']){
            $argc += [
                'createTime >'=> strtotime($_GET['startTime']),
            ];
        }

        if(isset($_GET['endTime'])  && $_GET['endTime']){
            $argc += [
                'createTime <'=> strtotime($_GET['endTime']),
            ];
        }

        //两个类型退货统计和换货统计
        $type = isset($_GET['type']) ? $_GET['type'] : 'put';

        //搜索项目名
        if(isset($_GET['search']) && $_GET['search']){
            $searchArg = [
                'field' => 'source',
                'arg'=> $_GET['search'],
                'side' => 'both'
            ];
        }else{
            $searchArg = '';
        }

//        __format($argc);

        $page_num = $this->config->item('fenye')['pageNum']; //每页的数据
        $start_position = ''; //初始数据
        $page = ($this->input->get('page')); //获取页码数量
        if(!$page){
            $num = 1;
            $start_position = ($num - 1) * $page_num;
        }else{
            $start_position = ($page - 1) * $page_num;
        }

        if(!$argc){
            $argc = 0;
        }

        $field = '*';
        //读取采购进货单的goodMessage数据。

        if($type == 'put'){
            if($searchArg){
//                $data = $this->stockPut_model->search($field,$argc,$searchArg,$page_num,$start_position);

                $data = $this->stockPut_model->getDataSearch($field,$argc,$searchArg);

            }else{
//                $data = $this->stockPut_model->page('stockPut', $argc, $page_num, $start_position, $field);

                $data[0] = $this->stockPut_model->getData('*',1);


            }
        }elseif ($type == 'out'){
            if($searchArg){
//                $data = $this->stockOut_model->search($field,$argc,$searchArg,$page_num,$start_position);

                $data = $this->stockOut_model->getDataSearch($field,$argc,$searchArg);


            }else{
//                $data = $this->stockOut_model->page('stockOut', $argc, $page_num, $start_position, $field);

                $data[0] = $this->stockOut_model->getData('*',1);


            }
        }

        $error = [
            'error' => true,
            'info' => '没有查询到信息'
        ];

        if(!$data[0]){
            die(json_encode($error,JSON_UNESCAPED_UNICODE));
        }

        if($data[0]){
            foreach ($data[0] as $k => $v) {
                $data[0][$k]['goodsMessage'] = json_decode($data[0][$k]['goodsMessage'], true);

                $arg = [
                    'name' => $v['source']
                ];
                $project[] = $this->project_model->getByFieldQueryData('id,name,source,code,linkMan,createTime', $arg, 0);
            }


//        print_r($project);die;

            foreach ($data[0] as $k2 => $v2) {
                $res[0][$v2['source']][] = $v2;
            }

//        __format($res);

            foreach ($res[0] as $k3 => $v3) {



                //预定义变量防止报错Undefined index：xxxx
                $res[0][$k3]['quantity'] = [];
                $res[0][$k3]['priceAll'] = [];

                foreach ($v3 as $k4 => $v4) {
                    //查询总商品数量和采购金额
                    $res[0][$k3]['quantity'][] .= array_sum(array_column($v4['goodsMessage'], 'quantity'));
                    $res[0][$k3]['priceAll'][] .= array_sum(array_column($v4['goodsMessage'], 'priceAll'));

                    //出入库单据创建人员
                    $res[0][$k3]['createMan'] = $v4['createMan'];
                    $res[0][$k3]['source'] = $v4['source'];


                }

                foreach ($project as $v5) {
                    if ($k3 == $v5['name']) {
                        $res[0][$k3]['code'] = $v5['code'];
                        $res[0][$k3]['projectId'] = $v5['id'];
                        $res[0][$k3]['linkMan'] = $v5['linkMan'];
                        $res[0][$k3]['createTime'] = $v5['createTime'];
                        $res[0][$k3]['projectsource'] = $v5['source'];

                    }
                }
            }


            //删除多余数据
            foreach ($res[0] as $k6 => $v6) {
                foreach ($v6 as $k7 => $v7) {
                    if (is_numeric($k7)) {
                        unset($res[0][$k6][$k7]);
                    }
                }

            }
        }


        $res['pageNum'] = $page_num;
        //如果$page 为空则为默认数量
        $res['this_page'] = $page;
        $res['total_num'] = count($res);
        $res['type'] = $type;

        echo json_encode($res, JSON_UNESCAPED_UNICODE);
    }

	/**
	 * 功能: 采购统计汇总, 按项目分类的点击数量弹窗接口
	 */
	public function projectContent()
	{
		// 通过项目id查出项目的source
		$projectId = $this->input->get('projectId'); // 项目id
		$rowset    = $this->project_model->getByFieldQueryData('name', array('id' => $projectId));
		$source    = $rowset['name'];

		$page_num 		= $this->config->item('fenye')['pageNum']; //每页的数据
        $start_position = 0; //初始数据
        $Currentpage 	= $this->input->get('page'); //获取页码数量        
        if ($Currentpage) {
            $start_position = ($Currentpage - 1) * $page_num;
        }
		// get安全处理

        $fields = 'goodsMessage,createTime,endTime';
		$where  = [
			'status' => 5,
			'source' => $source		
		];
        // 读取项目下的goodsMessage数据。
        $data   = $this->purchaseOrder_model->paging($fields, $where, $page_num, $start_position);

		if ($data['total_num'] != 0) {
			// 得到总数
			$totalNum   = $data['total_num'];
			unset($data['total_num']);
			// 得到需要的商品信息
			foreach ($data as $k => $v) {
				// 格式化goodsMessage json字符串
                $data[$k]['goodsMessage'] = json_decode($data[$k]['goodsMessage'], true);
				foreach ($data[$k]['goodsMessage'] as $k2 => $v2) {
					$data[$k]['goodsMessage'][$k2]['createTime'] = $v['createTime'];
					$data[$k]['goodsMessage'][$k2]['endTime'] = $v['endTime'];
				}
			}

			// 把多余的去掉
			foreach ($data as $k3 => $v3) {
				$goodsArr[] = $v3['goodsMessage'];
			}
			// 因为只能是一个项目名称为主, 所以去掉第一个最外层就好
			$goodsArr = reset($goodsArr);
			foreach ($goodsArr as $v4) {
				if (!$v4['stockPriceId']) continue;
				$goods[] = $v4;
			}
//			dd($goods);
			$viewData = [
				'goods' 	  => $goods,
				'totalNmu'    => $totalNum,
				'pageNum'     => $page_num,
				'currentPage' => $Currentpage
			];
			echo json_encode($viewData, JSON_UNESCAPED_UNICODE);
		} else {
			$data = '数据错误!';
			echo $data;
		}
	}
	
	/**
	 * 功能: 按供应商类别统计, 退货商品数量的点击数量弹窗接口
	 */
	public function returnContent()
	{
		// 获取$_GET
		$get  = $this->input->get();
		
		// 通过supplierId 搜索出供应商结果集
		$supplierId = $get['supplierId'];
		$rowset		= $this->supplier_model->getByFieldQueryData('name', array('id' => $supplierId));

		// 再根据供应商的名字查询退货单里的退货商品
		$fields 	= 'goodsMessage, supplier, createTime, endTime';
		$where  	= [
			'type'     => '采购退货单',
			'supplier' => $rowset['name']
		];
		$data = $this->returnOrder_model->findData($fields, $where);
	
		if ($data) {
			// 得到需要的商品信息
			foreach ($data as $k => $v) {
				// 格式化goodsMessage json字符串
                $data[$k]['goodsMessage'] = json_decode($data[$k]['goodsMessage'], true);
				foreach ($data[$k]['goodsMessage'] as $k2 => $v2) {
					$data[$k]['goodsMessage'][$k2]['createTime'] = $v['createTime'];
					$data[$k]['goodsMessage'][$k2]['endTime'] 	 = $v['endTime'];
					$data[$k]['goodsMessage'][$k2]['supplier'] 	 = $v['supplier'];
				}
			}			
//			dd($data);
			// 把多余的去掉, 再组成商品结果集
			foreach ($data as $k3 => $v3) {
				$goodsArr[] = $v3['goodsMessage'];				
			}
		
			foreach ($goodsArr as $k4 => $v4) {
				foreach ($v4 as $k5 => $v5) {
					if (!is_numeric(stripos($v5['specification'], '商品规格'))) {
						$goods[] = $v5;
					}					
				}
			}

			foreach ($goods as $k5 => $v5) {
				$goodsInfo[] = $this->goods_model->getByFieldQueryData('one_category, product_no', array('product_no' => $v5['product_no']));
			}
			$goodsInfo = array_filter($goodsInfo);

			// 2物料包、3书籍、4机器耗材、9打印机租赁、8供应商商品
            foreach ($goodsInfo as $k6 => $v6) {
                switch ($v6['one_category']){
                    case 2:
                        $goodsInfo[$k6]['one_category'] = "物料包";
                        break;
                    case 3:
                        $goodsInfo[$k6]['one_category'] = "书籍";
                        break;
                    case 4:
                        $goodsInfo[$k6]['one_category'] = "机器耗材";
                        break;
                    case 8:
                        $goodsInfo[$k6]['one_category'] = "供应商商品";
                        break;
                    case 9:
                        $goodsInfo[$k6]['one_category'] = "打印机租赁";
                        break;
                }
            }
//				dd($goodsInfo);
			foreach ($goods as $k7 => $v7) {
				foreach ($goodsInfo as $v8) {
					if ($v7['product_no'] == $v8['product_no']) {
						$goods[$k7]['one_category'] = $v8['one_category'];
					} else {
						$goods[$k7]['one_category'] = '无分类';
					}
				}	
			}
//				dd($goods);
			// 已取出数组, 搜索数组
			
			// 已取出数组, 接下来就是数组查询+分页
			$page_num 		= $this->config->item('fenye')['pageNum']; //每页的数据
			$currentPage 	= $this->input->get('page'); //获取页码数量     
			$viewData 		= page_array($page_num, $currentPage, $goods);

			echo json_encode($viewData, JSON_UNESCAPED_UNICODE);
		} else {
			echo '数据错误';
			exit;
		}	
	}
		
		
		// 再根据供应商的名字查询退货单里的退货商品
//		$page_num 		= $this->config->item('fenye')['pageNum']; //每页的数据
//      $start_position = 0; //初始数据
//      $currentPage 	= $this->input->get('page'); //获取页码数量     
//      if ($currentPage) {
//          $start_position = ($currentPage - 1) * $page_num;
//      }

//		$fields 	= 'goodsMessage, supplier, createTime, endTime';
//		$where  	= [
//			'type'     => '采购退货单',
//			'supplier' => $rowset['name']
//		];
//		$data = $this->returnOrder_model->paging($fields, $where, $page_num, $start_position);
////		dd($data);
//		if ($data['total_num'] != 0) {
//			// 得到总数
//			$totalNum = $data['total_num'];
//			unset($data['total_num']);
//			
//			// 得到需要的商品信息
//			foreach ($data as $k => $v) {
//				// 格式化goodsMessage json字符串
//              $data[$k]['goodsMessage'] = json_decode($data[$k]['goodsMessage'], true);
//				foreach ($data[$k]['goodsMessage'] as $k2 => $v2) {
//					$data[$k]['goodsMessage'][$k2]['createTime'] = $v['createTime'];
//					$data[$k]['goodsMessage'][$k2]['endTime'] = $v['endTime'];
//					$data[$k]['goodsMessage'][$k2]['supplier'] = $v['supplier'];
//				}
//			}			
////			dd($data);
//			// 把多余的去掉, 再组成商品结果集
//			foreach ($data as $k3 => $v3) {
//				$goodsArr[] = $v3['goodsMessage'];				
//			}
//		
//			foreach ($goodsArr as $k4 => $v4) {
//				foreach ($v4 as $k5 => $v5) {
//					if (!is_numeric(stripos($v5['specification'], '商品规格'))) {
//						$goods[] = $v5;
//					}					
//				}
//			}
////			$totalNum = count($goods);
////			dd($goods);
//			foreach ($goods as $k5 => $v5) {
//				$goodsInfo[] = $this->goods_model->getByFieldQueryData('one_category, product_no', array('product_no' => $v5['product_no']));
//			}
//			// 2物料包、3书籍、4机器耗材、9打印机租赁、8供应商商品
//          foreach ($goodsInfo as $k6 => $v6) {
//              switch ($v6['one_category']){
//                  case 2:
//                      $goodsInfo[$k6]['one_category'] = "物料包";
//                      break;
//                  case 3:
//                      $goodsInfo[$k6]['one_category'] = "书籍";
//                      break;
//                  case 4:
//                      $goodsInfo[$k6]['one_category'] = "机器耗材";
//                      break;
//                  case 8:
//                      $goodsInfo[$k6]['one_category'] = "供应商商品";
//                      break;
//                  case 9:
//                      $goodsInfo[$k6]['one_category'] = "打印机租赁";
//                      break;
//              }
//          }
//			foreach ($goods as $k7 => $v7) {
//				foreach ($goodsInfo as $v8) {
//					if ($v7['product_no'] == $v8['product_no']) {
//						$goods[$k7]['one_category'] = $v8['one_category'];
//					}
//				}	
//			}
//			
////			$viewData = [
////				'goods' 	  => $goods,
////				'totalNmu'    => $totalNum,
////				'pageNum'     => $page_num,
////				'currentPage' => $Currentpage
////			];
////			echo json_encode($viewData, JSON_UNESCAPED_UNICODE);
//			// 已取出数组, 接下来就是数组查询+分页
//			$page_num 		= $this->config->item('fenye')['pageNum']; //每页的数据
//			$currentPage 	= $this->input->get('page'); //获取页码数量     
//			$viewData 		= page_array($page_num, $currentPage, $goods);
//			echo json_encode($viewData, JSON_UNESCAPED_UNICODE);
//			
//		} else {
//			echo '数据错误!';
//			exit;
//		}
//	}
	
	/**
	 * 功能: 按供应商类别统计, 退货商品数量的点击数量弹窗接口后的搜索功能
	 */
	public function returnContentSearch()
	{
		// 获取$_GET 及条件 --条件有: 商品分类, 和商品编号, 当前页
		$get  = $this->input->get();
		
		// 搜索不到返回的error 的数据
		$error = [
	        'error' => true,
	        'info' => '没有查询到信息'
        ];
		
		// 搜索内容记得trim
		$search 	  = isset($get['search']) ? trim($get['search']) : '';
		$one_category = isset($get['one_category']) ? $get['one_category'] : ''; 
		
		// 判断搜索内容, 如果没有搜索, 则就不用进行数据查询
		if ($search ='' && $one_category='') {
			echo '请输入搜索内容';
			exit;
		} else {
			// 因为数组是拼接而来, 所以现之情况只能搜索数组再实行分页, 通过supplierId 搜索出供应商结果集
//			$supplierId = $get['supplierId'];
			$rowset		= $this->supplier_model->getByFieldQueryData('name', array('id' => 1));
//			dd($rowset);
			// 再根据供应商的名字查询退货单里的退货商品
			$fields 	= 'goodsMessage, supplier, createTime, endTime';
			$where  	= [
				'type'     => '采购退货单',
				'supplier' => $rowset['name']
			];
			$data = $this->returnOrder_model->findData($fields, $where);
	//		dd($data);
	
			if ($data) {
				// 得到需要的商品信息
				foreach ($data as $k => $v) {
					// 格式化goodsMessage json字符串
	                $data[$k]['goodsMessage'] = json_decode($data[$k]['goodsMessage'], true);
					foreach ($data[$k]['goodsMessage'] as $k2 => $v2) {
						$data[$k]['goodsMessage'][$k2]['createTime'] = $v['createTime'];
						$data[$k]['goodsMessage'][$k2]['endTime'] 	 = $v['endTime'];
						$data[$k]['goodsMessage'][$k2]['supplier'] 	 = $v['supplier'];
					}
				}			
	//			dd($data);
				// 把多余的去掉, 再组成商品结果集
				foreach ($data as $k3 => $v3) {
					$goodsArr[] = $v3['goodsMessage'];				
				}
			
				foreach ($goodsArr as $k4 => $v4) {
					foreach ($v4 as $k5 => $v5) {
						if (!is_numeric(stripos($v5['specification'], '商品规格'))) {
							$goods[] = $v5;
						}					
					}
				}
	
				foreach ($goods as $k5 => $v5) {
					$goodsInfo[] = $this->goods_model->getByFieldQueryData('one_category, product_no', array('product_no' => $v5['product_no']));
				}
				$goodsInfo = array_filter($goodsInfo);

				// 2物料包、3书籍、4机器耗材、9打印机租赁、8供应商商品
	            foreach ($goodsInfo as $k6 => $v6) {
	                switch ($v6['one_category']){
	                    case 2:
	                        $goodsInfo[$k6]['one_category'] = "物料包";
	                        break;
	                    case 3:
	                        $goodsInfo[$k6]['one_category'] = "书籍";
	                        break;
	                    case 4:
	                        $goodsInfo[$k6]['one_category'] = "机器耗材";
	                        break;
	                    case 8:
	                        $goodsInfo[$k6]['one_category'] = "供应商商品";
	                        break;
	                    case 9:
	                        $goodsInfo[$k6]['one_category'] = "打印机租赁";
	                        break;
	                }
	            }
//				dd($goodsInfo);
				foreach ($goods as $k7 => $v7) {
					foreach ($goodsInfo as $v8) {
						if ($v7['product_no'] == $v8['product_no']) {
							$goods[$k7]['one_category'] = $v8['one_category'];
						} else {
							$goods[$k7]['one_category'] = '无分类';
						}
					}	
				}
//				dd($goods);
				// 已取出数组, 搜索数组
				
				// 已取出数组, 接下来就是数组查询+分页
				$page_num 		= $this->config->item('fenye')['pageNum']; //每页的数据
				$currentPage 	= $this->input->get('page'); //获取页码数量     
				$viewData 		= page_array($page_num, $currentPage, $goods);

				echo json_encode($viewData, JSON_UNESCAPED_UNICODE);
			} else {
				echo '数据错误';
				exit;
			}	
		}
	}
	
	/**
	 * 功能: 按供应商类别统计, 退货统计中采购商品数量的点击数量弹窗接口
	 */
	public function returnPurchaseContent()
	{
		// 通过supplierId 搜索出供应商结果集
		$supplierId = $this->input->get('supplierId');
		$rowset		= $this->supplier_model->getByFieldQueryData('name', array('id' => $supplierId));
		
		// 再根据供应商的名字查询退货单里的退货商品
		$page_num 		= $this->config->item('fenye')['pageNum']; //每页的数据
        $start_position = 0; //初始数据
        $Currentpage 	= $this->input->get('page'); //获取页码数量     
        if ($Currentpage) {
            $start_position = ($Currentpage - 1) * $page_num;
        }

		$fields 	= 'goodsMessage, supplier, createTime, endTime';
		$where  	= [
			'type'     => '采购进货单',
			'supplier' => $rowset['name']
		];
		$data = $this->purchaseOrder_model->paging($fields, $where, $page_num, $start_position);
//		dd($data);
		if ($data['total_num'] != 0) {
			// 得到总数
			$totalNum = $data['total_num'];
			unset($data['total_num']);
			
			// 得到需要的商品信息
			foreach ($data as $k => $v) {
				// 格式化goodsMessage json字符串
                $data[$k]['goodsMessage'] = json_decode($data[$k]['goodsMessage'], true);
				foreach ($data[$k]['goodsMessage'] as $k2 => $v2) {
					$data[$k]['goodsMessage'][$k2]['createTime'] = $v['createTime'];
					$data[$k]['goodsMessage'][$k2]['endTime'] = $v['endTime'];
					$data[$k]['goodsMessage'][$k2]['supplier'] = $v['supplier'];
				}
			}			
//			dd($data);
			// 把多余的去掉, 再组成商品结果集
			foreach ($data as $k3 => $v3) {
				$goodsArr[] = $v3['goodsMessage'];				
			}
		
			foreach ($goodsArr as $k4 => $v4) {
				foreach ($v4 as $k5 => $v5) {
					if (!is_numeric(stripos($v5['specification'], '商品规格'))) {
						$goods[] = $v5;
					}					
				}
			}
//			$totalNum = count($goods);
//			dd($goods);
			foreach ($goods as $k5 => $v5) {
				$goodsInfo[] = $this->goods_model->getByFieldQueryData('one_category, product_no', array('product_no' => $v5['product_no']));
			}
			// 2物料包、3书籍、4机器耗材、9打印机租赁、8供应商商品
            foreach ($goodsInfo as $k6 => $v6) {
                switch ($v6['one_category']){
                    case 2:
                        $goodsInfo[$k6]['one_category'] = "物料包";
                        break;
                    case 3:
                        $goodsInfo[$k6]['one_category'] = "书籍";
                        break;
                    case 4:
                        $goodsInfo[$k6]['one_category'] = "机器耗材";
                        break;
                    case 8:
                        $goodsInfo[$k6]['one_category'] = "供应商商品";
                        break;
                    case 9:
                        $goodsInfo[$k6]['one_category'] = "打印机租赁";
                        break;
                }
            }
			foreach ($goods as $k7 => $v7) {
				foreach ($goodsInfo as $v8) {
					if ($v7['product_no'] == $v8['product_no']) {
						$goods[$k7]['one_category'] = $v8['one_category'];
					}
				}	
			}
//			dd($goods);
			$viewData = [
				'goods' 	  => $goods,
				'totalNmu'    => $totalNum,
				'pageNum'     => $page_num,
				'currentPage' => $Currentpage
			];
			echo json_encode($viewData, JSON_UNESCAPED_UNICODE);
			
		} else {
			$data = '数据错误!';
			echo $data;
		}
	}
	
	/**
	 * 功能: 按供应商类别统计, 退货统计中采购商品数量的点击数量弹窗接口的搜索功能
	 */
	public function returnPurchaseContentSearch()
	{
		// 获取$_GET 及条件 --条件有: 商品分类, 和商品编号, 当前页
		$get   = $this->input->get();
		$where = [];
		// one_category 是一级分类...
		if ($get['one_category']) {
			$where += [
				'one_category' => $get['one_category']
			];
		}	
		
	}
	
	/**
	 * 功能: 按供应商类别统计, 换货商品数量的点击数量弹窗接口后的搜索功能
	 */
	public function barterContent()
	{
		// 通过supplierId 搜索出供应商结果集
		$supplierId = $this->input->get('supplierId');
		$rowset		= $this->supplier_model->getByFieldQueryData(' name', array('id' => $supplierId));
		
		// 再根据供应商的名字查询退货单里的退货商品
		$page_num 		= $this->config->item('fenye')['pageNum']; //每页的数据
        $start_position = 0; //初始数据
        $Currentpage 	= $this->input->get('page'); //获取页码数量        
        if ($Currentpage) {
            $start_position = ($Currentpage - 1) * $page_num;
        }

		$supplier	= $rowset['name'];
		$fields 	= 'goodsMessage, supplier, createTime, endTime';
		$where  	= [
			'type'     => '采购换货单',
			'supplier' => $supplier	
		];
		$data = $this->returnOrder_model->paging($fields, $where, $page_num, $start_position);
//		dd($data);
		if ($data['total_num'] != 0) {
			// 得到总数
			$totalNum = $data['total_num'];
			unset($data['total_num']);
			
			// 得到需要的商品信息
			foreach ($data as $k => $v) {
				// 格式化goodsMessage json字符串
                $data[$k]['goodsMessage'] = json_decode($data[$k]['goodsMessage'], true);
				foreach ($data[$k]['goodsMessage'] as $k2 => $v2) {
					$data[$k]['goodsMessage'][$k2]['createTime'] = $v['createTime'];
					$data[$k]['goodsMessage'][$k2]['endTime'] = $v['endTime'];
					$data[$k]['goodsMessage'][$k2]['supplier'] = $v['supplier'];
				}
			}			
			
			// 把多余的去掉, 再组成商品结果集
			foreach ($data as $k3 => $v3) {
				$goodsArr[] = $v3['goodsMessage'];				
			}

			foreach ($goodsArr as $k4 => $v4) {
				foreach ($v4 as $k5 => $v5) {
					if (!$v5['price']) continue;
					$goods[] = $v5;
				}
			}
	
			$viewData = [
				'goods' 	  => $goods,
				'totalNmu'    => $totalNum,
				'pageNum'     => $page_num,
				'currentPage' => $Currentpage
			];
			echo json_encode($viewData, JSON_UNESCAPED_UNICODE);
			
		} else {
			$data = '数据错误!';
			echo $data;
		}
	}
	
	
}











































